<?php
namespace app\api\controller;

use app\BaseController;

class MY extends BaseController
{
    /**
     * 状态码
     */
    const CODE = [
        0 => "success",
        1 => "fail",
        2 => "paramError",
    ];

    /**
     * 格式化返回数据
     * @param int $c
     * @param string $m
     * @param $d
     * @return string
     */
    public function returnJson(int $c, $d, string $m=""): string
    {
        $m || $m = self::CODE[$c];
        return jsonData([
            'code' => $c,
            'msg'  => $m,
            'data' => $d
        ]);
    }

    /**
     * 格式化输出数据
     * @param int $c
     * @param string $m
     * @param $d
     * @return string
     */
    public function echoJson(int $c, $d, string $m=""): string
    {
        $m || $m = self::CODE[$c];
        exit(jsonData([
            'code' => $c,
            'msg'  => $m,
            'data' => $d
        ]));
    }

}